package com.ktwlsoft.archivemanage.controller.export;

import com.ktwlsoft.archivemanage.domain.business.businessService.export.ExportService;
import com.ktwlsoft.archivemanage.domain.business.repositoryService.OperationRepositoryService;
import com.ktwlsoft.archivemanage.domain.dao.entity.OperationLog;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.businessInspect.BusinessInspectFindPageRequest;
import com.ktwlsoft.archivemanage.payload.guiBusiness.GuiBusinessPageRequest;
import com.ktwlsoft.archivemanage.payload.guiBusiness.GuidanceMendListBatchExportRequest;
import com.ktwlsoft.archivemanage.payload.mendList.MendListPageRequest;
import com.ktwlsoft.archivemanage.payload.operationLog.SaveLogRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 导出
 *
 * @author zhuhe on 2019/11/12 11:01
 * @version 1.0
 */
@Api(value = "导出", description = "导出")
@RestController
@RequestMapping("export")
public class ExportController {

    /**导出*/
    private final ExportService exportService;

    public ExportController(ExportService exportService) {
        this.exportService = exportService;
    }

    /**
      * 整改单批量导出 on 2019/11/12 11:02
      *
      * @param request request
      * @param response response
      */
    @ApiOperation(value = "整改单批量导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("mendListBatchExport")
    public void mendListBatchExport(MendListPageRequest request, HttpServletResponse response){
        exportService.mendListBatchExport(request,response);
    }


    /**
     * 保存整改单批量导出操作记录 on 2019/11/12 11:02
     */
    @ApiOperation(value = "保存整改单批量导出操作记录", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("savemendListBatchExport")
    public ResponseEntity<?> savemendListBatchExport(){
        OperationRepositoryService.saveLog(new SaveLogRequest(
                OperationLog.OperationType.EXPORT_BATCH,
                "批量检查整改数据",
                "检查整改",
                OperationLog.BusinessType.BUSINESS
        ));
        return ResponseEntity.ok(Result.ok("操作成功"));
    }

    /**
     * 检查整改整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "检查整改整份导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("mendListWholeExport")
    public ResponseEntity<?> mendListWholeExport(@ApiParam(name = "id", value = "整改单id") @RequestParam(defaultValue = "", required = false) Long id,
                                                 @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                 HttpServletRequest request){
        return exportService.mendListWholeExport(id,userId,request);
    }

    /**
     * 自查复查检查整改整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "自查复查检查整改整份导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("selfOrRepeatMendListWholeExport")
    public ResponseEntity<?> selfOrRepeatMendListWholeExport(@ApiParam(name = "id", value = "整改单id") @RequestParam(defaultValue = "", required = false) Long id,
                                                             @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                             HttpServletRequest request){
        return exportService.selfOrRepeatMendListWholeExport(id,userId,request);
    }

    /**
     * 检查整改文件导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "检查整改文件导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("mendListFileExport")
    public ResponseEntity<?> mendListFileExport(@ApiParam(name = "id", value = "整改单id") @RequestParam(defaultValue = "", required = false) Long id,
                                                @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                HttpServletRequest request){
        return exportService.mendListFileExport(id,userId,request);
    }

    /**
     * 业务检查批量导出 on 2019/11/12 11:02
     *
     * @param response response
     */
    @ApiOperation(value = "业务检查批量导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("businessGuidanceBatchExport")
    public void businessGuidanceBatchExport(BusinessInspectFindPageRequest request, HttpServletResponse response){
        exportService.businessGuidanceBatchExport(request,response);
        OperationRepositoryService.saveLog(new SaveLogRequest(
                OperationLog.OperationType.EXPORT_BATCH,
                "批量导出业务检查数据",
                "业务检查",
                OperationLog.BusinessType.BUSINESS
        ));
    }

    /**
     * 保存业务检查批量导出操作记录 on 2019/11/12 11:02
     */
    @ApiOperation(value = "保存业务检查批量导出操作记录", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("saveBusinessGuidanceBatchExport")
    public ResponseEntity<?> saveBusinessGuidanceBatchExport(){
        OperationRepositoryService.saveLog(new SaveLogRequest(
                OperationLog.OperationType.EXPORT_BATCH,
                "批量导出业务检查数据",
                "业务检查",
                OperationLog.BusinessType.BUSINESS
        ));
        return ResponseEntity.ok(Result.ok("操作成功"));
    }

    /**
     * 保存指导整改批量导出操作记录 on 2019/11/12 11:02
     */
    @ApiOperation(value = "保存指导整改批量导出操作记录", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("saveGuidanceBatchExport")
    public ResponseEntity<?> saveGuidanceBatchExport(){
        OperationRepositoryService.saveLog(new SaveLogRequest(
                OperationLog.OperationType.EXPORT_BATCH,
                "批量导出指导整改数据",
                "指导整改",
                OperationLog.BusinessType.BUSINESS
        ));
        return ResponseEntity.ok(Result.ok("操作成功"));
    }

    /**
     * 业务检查整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "业务检查整份导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("businessGuidanceWholeExport")
    public ResponseEntity<?> businessGuidanceWholeExport(@ApiParam(name = "id", value = "业务检查id") @RequestParam(defaultValue = "", required = false) Long id,
                                                         @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                 HttpServletRequest request){
        return exportService.businessGuidanceWholeExport(id,userId,request);
    }

    /**
     * 自查复查业务检查整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "自查复查业务检查整份导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("selfOrRepeatBusinessGuidanceWholeExport")
    public ResponseEntity<?> selfOrRepeatBusinessGuidanceWholeExport(@ApiParam(name = "id", value = "业务检查id") @RequestParam(defaultValue = "", required = false) Long id,
                                                                     @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                                     HttpServletRequest request){
        return exportService.selfOrRepeatBusinessGuidanceWholeExport(id,userId,request);
    }

    /**
     * 业务检查文件导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "业务检查文件导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("businessGuidanceFileExport")
    public ResponseEntity<?> businessGuidanceFileExport(@ApiParam(name = "id", value = "业务检查id") @RequestParam(defaultValue = "", required = false) Long id,
                                                        @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                HttpServletRequest request){
        return exportService.businessGuidanceFileExport(id,userId,request);
    }

    /**
     * 指导整改单批量导出 on 2019/11/12 11:02
     *
     * @param request request
     * @param response response
     */
    @ApiOperation(value = "指导整改单批量导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("guidanceMendListBatchExport")
    public void guidanceMendListBatchExport(GuidanceMendListBatchExportRequest request, HttpServletResponse response){
        exportService.guidanceMendListBatchExport(request,response);
    }

    /**
     * 指导整改整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "指导整改整份导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("guiMendListWholeExport")
    public ResponseEntity<?> guiMendListWholeExport(@ApiParam(name = "id", value = "指导整改id") @RequestParam(defaultValue = "", required = false) Long id,
                                                    @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                    HttpServletRequest request){
        return exportService.guiMendListWholeExport(id,userId,request);
    }

    /**
     * 指导整改文件导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "指导整改文件导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("guiMendListFileExport")
    public ResponseEntity<?> guiMendListFileExport(@ApiParam(name = "id", value = "指导整改id") @RequestParam(defaultValue = "", required = false) Long id,
                                                   @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                   HttpServletRequest request){
        return exportService.guiMendListFileExport(id,userId,request);
    }

    /**
     * 业务指导批量导出 on 2019/11/12 11:02
     *
     * @param response response
     */
    @ApiOperation(value = "业务指导批量导出")
    @ResponseBody
    @GetMapping("guidanceBatchExport")
    public void guidanceBatchExport(GuiBusinessPageRequest request, HttpServletResponse response){
        exportService.guidanceBatchExport(request,response);
        OperationRepositoryService.saveLog(new SaveLogRequest(
                OperationLog.OperationType.EXPORT_BATCH,
                "批量导出业务指导数据",
                "业务指导",
                OperationLog.BusinessType.BUSINESS
        ));
    }

    /**
     * 业务指导整份导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "业务指导整份导出")
    @ResponseBody
    @GetMapping("guidanceWholeExport")
    public ResponseEntity<?> guidanceWholeExport(@ApiParam(name = "id", value = "业务指导id") @RequestParam(defaultValue = "", required = false) Long id,
                                                 @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                 HttpServletRequest request){
        return exportService.guidanceWholeExport(id,userId,request);
    }

    /**
     * 业务指导文件导出 on 2019/11/12 11:02
     *
     * @param id id
     * @param request request
     */
    @ApiOperation(value = "业务指导文件导出", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("guidanceFileExport")
    public ResponseEntity<?> guidanceFileExport(@ApiParam(name = "id", value = "业务检查id") @RequestParam(defaultValue = "", required = false) Long id,
                                                @ApiParam(name = "userId", value = "用户id") @RequestParam(defaultValue = "", required = false) Long userId,
                                                HttpServletRequest request){
        return exportService.guidanceFileExport(id,userId,request);
    }
}